// on document-ready
$(function(){
	$("#main_menu strong").each(function(){
		var speed = 500;
		
		$(this).click(function(){
			var strong = $(this);
			var li = strong.parent();
			var ul = li.children("ul").eq(0)
			if(li.hasClass("opened")){
				ul.slideUp(speed, "easeOutExpo", function(){
					li.removeClass("opened");
					MenuSave();
				});
			}else{
				ul.slideDown(speed, "easeOutExpo", function(){
					li.addClass("opened");
					MenuSave();
				});
			}
		});
	});
});

function MenuSave(){
	var opened = "";
	$("#main_menu > li").each(function(){
		if($(this).hasClass("opened")){
			opened += "|" + $(this).children("strong").html();
		}
	});
	opened = opened.replace(/^\|/,"");
	
	Cookie.write("menu",opened, 15);
}

var Cookie = {
	_c: null,
	c: {},
	parse: function(){
		var tmp;
		this._c = document.cookie;
		var c = _c.split(";");
		for(var i=0; i<c.length; i++){
			tmp = c[i].split("=", 2);
			this.c[tmp[0]] = tmp[1];
		}
	},
	read: function(name){
		this.parse();
		console.dir(this.c);
	},
	write: function(name, value, expire){
		expire = parseInt(expire)>0 ? expire : 0;
		
		var today = new Date();
		var expire_date = new Date(today.getTime() + expire*1000*60*60*24)
		
		document.cookie = name + "=" + escape(value) + ";expires=" + expire_date.toGMTString() + ";path=/";
	}
};